package com.clkj.aimin.controller;

import com.clkj.aimin.pojo.common.Result;
import com.clkj.aimin.pojo.common.StatusCode;
import com.clkj.aimin.pojo.notice.Notice;
import com.clkj.aimin.service.notice.NoticeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yawang
 * @create 2024/06/12 09:12:48
 **/
@RestController
@RequestMapping("/notice")
@CrossOrigin
@Api(value = "/notice", tags = {"公告、文章管理"})
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    @PostMapping("/addNotice")
    @ApiOperation(value = "后台添加公告")
    public Result addNotice(@RequestBody  Notice notice) {
        try {
            noticeService.addNotice(notice);
            return new Result(true, StatusCode.OK,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }
    }

    @PostMapping("/listNotice")
    @ApiOperation(value = "后台获取公告列表")
    public Result listNotice(){
        try {
            List<Notice> notices = noticeService.listNotice();
            return new Result(true, StatusCode.OK,"获取成功",notices);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"获取失败");
        }
    }

    @PostMapping("/updateNotice")
    @ApiOperation(value = "后台更新公告")
    public Result updateNotice(Notice notice){
        try {
            noticeService.updateNotice(notice);
            return new Result(true, StatusCode.OK,"更新成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"更新失败");
        }
    }

    @PostMapping("/deleteNotice")
    @ApiOperation(value = "后台删除公告")
    public Result deleteNotice(Integer noticeId){
        try {
            noticeService.deleteNotice(noticeId);
            return new Result(true, StatusCode.OK,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"删除失败");
        }
    }

    @PostMapping("/updateNoticeStatus")
    @ApiOperation(value = "后台更新公告状态")
    public Result updateNoticeStatus(Integer status,String ids){
        try {
            noticeService.updateNoticeStatus(status,ids);
            return new Result(true, StatusCode.OK,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"删除失败");
        }
    }

    @PostMapping("/listTopic")
    @ApiOperation(value = "后台获取文章视频列表")
    public Result listTopic(Integer page,Integer size,Integer doctorId,String topicName,Integer topicType){
        try {
            PageInfo results = noticeService.listTopic(page,size,doctorId,topicName,topicType);
            return new Result(true, StatusCode.OK,"删除成功",results);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"删除失败");
        }
    }

}
